﻿using System;
using System.Collections.Generic;

namespace DigitalQuran.Qnl
{
    /// <summary>
    /// Holds Parser Errors in Runtime
    /// </summary>
    public class ParseErrors : List<ParseError>
    {
        internal void Add(QnlException ex)
        {
            this.Add(new ParseError(ex.Index, ex.Length, ex.Message));
        }

        internal void Add(Exception ex)
        {
            this.Add(new ParseError(0, 0, ex.Message));
        }
    }

    /// <summary>
    /// Represent Parse Error
    /// </summary>
    public sealed class ParseError
    {
        /// <summary>
        /// Gets a message that describes the current error
        /// </summary>
        public string Message { get; private set; }

        /// <summary>
        /// Gets zero based index of start of error
        /// </summary>
        public int Index { get; internal set; }

        /// <summary>
        /// Gets length of error
        /// </summary>
        public int Length { get; internal set; }

        /// <summary>
        /// Creates new instance of <see cref="DigitalQuran.Qnl.ParseError"/>
        /// </summary>
        /// <param name="index">Index of Error Location</param>
        /// <param name="length">Length of error</param>
        /// <param name="message">Message to associated with error</param>
        public ParseError(int index, int length, string message)
        {
            this.Index = index;            
            this.Message = message;
            this.Length = length;
        }
    }
}